package at.fhooe.mcm12.java.sim;

import java.io.*;

public class GPSSimulator extends BufferedReader{

	private int m_updateFrequency;
	private String m_filter;
	
	public GPSSimulator(String _gpsLogFile, int _updateFrequency, String _filter) throws FileNotFoundException {
		super(new FileReader(_gpsLogFile));
		
		m_updateFrequency = _updateFrequency;
		m_filter = _filter;
	}
	
	public int getUpdateFrequency()
	{
		return m_updateFrequency;
	}
	
	public void setUpdateFrequency(int _updateFrequency)
	{
		m_updateFrequency = _updateFrequency;
	}

	public String readLine()
	{	
		String[] split;
		String line = "";
		
		try 
		{	
			line = super.readLine();
			
			if(line != null)
			{
				split = line.split(",");

				if(split[0].compareTo(m_filter)==0)
				{
					Thread.sleep(m_updateFrequency);
				}
			}
		} 
		catch (IOException e) 
		{
			System.err.println(e.getMessage());
		}
		catch (InterruptedException ie)
		{
			System.err.println(ie.getMessage());
		}
		
		if(line != null)
		{
			return line;
		}
		else
		{
			return "#reset";
		}
	}
}
